﻿//using SkiaSharp;
using System;

namespace EasyNet
{
    //static public class ImageTools
    //{
    //    /// <summary>
    //    /// 压缩图片方法
    //    /// </summary>
    //    /// <param name="bitmap_">图片</param>
    //    /// <param name="dest_height">picturebox控件高</param>
    //    /// <param name="dest_width">picturebox控件宽</param>
    //    /// <returns></returns>
    //    static public SKImage ZoomImage(SKImage bitmap_, int dest_height, int dest_width)
    //    {
    //        try
    //        {
    //            SKImage sourImage = bitmap_;
    //            int width = 0, height = 0;
    //            //按比例缩放             
    //            int sourWidth = sourImage.Width;
    //            int sourHeight = sourImage.Height;
    //            if (sourHeight > dest_height || sourWidth > dest_width)
    //            {
    //                if ((sourWidth * dest_height) > (sourHeight * dest_width))
    //                {
    //                    width = dest_width;
    //                    height = (dest_width * sourHeight) / sourWidth;
    //                }
    //                else
    //                {
    //                    height = dest_height;
    //                    width = (sourWidth * dest_height) / sourHeight;
    //                }
    //            }
    //            else
    //            {
    //                width = sourWidth;
    //                height = sourHeight;
    //            }
    //            SKSurface skSurface = SKSurface.Create(new SKImageInfo(dest_width, dest_height));
    //            SKCanvas skCanvas = skSurface.Canvas;
    //            skCanvas.Clear(Color.Transparent);
    //            //设置画布的描绘质量           
    //            skCanvas.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    //            skCanvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    //            skCanvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    //            skCanvas.DrawImage(sourImage, new Rectangle((dest_width - width) / 2, (dest_height - height) / 2, width, height), 0, 0, sourImage.Width, sourImage.Height, GraphicsUnit.Pixel);
    //            //g.DrawImage(sourImage, new Rectangle(0, 0, destWidth, destHeight), new Rectangle(0, 0, sourImage.Width, sourImage.Height), GraphicsUnit.Pixel);
    //            skCanvas.Dispose();
    //            //设置压缩质量       
    //            System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
    //            long[] quality = new long[1];
    //            quality[0] = 100;
    //            System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
    //            encoderParams.Param[0] = encoderParam;
    //            sourImage.Dispose();
    //            return destBitmap;
    //        }
    //        catch (Exception exception)
    //        {
    //            return bitmap_;
    //        }
    //    }
    //}
}
